using System.Collections.Generic;

namespace LambdaGp.Core.GeneticOperator
{
    public class PointMutation : GeneticOperator
    {
        public PointMutation(Population population)
            : base(population)
        {
        }

        public override OperatorNode Execute(OperatorNode operatorNode, GenomeDefinition genomeDefinition)
        {
            List<OperatorNode> list = operatorNode.OperatorTreeToList();
            OperatorNode nodeToMutate = list.GetRandomItem();
            List<Operator> operators = genomeDefinition.GetOperatorsByArity(nodeToMutate.Operator.Arity);
            Operator @operator = operators.GetRandomItem();
            nodeToMutate.Operator = @operator;
            return operatorNode;
        }
    }
}
